package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.DealDetailBean;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.my.DealDetailPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.util.StringUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IDealDetailView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/6/9.
 * Desc   : 交易明细Activity
 */

public class DealDetailsActivity extends BaseActivity<DealDetailPresenter> implements IDealDetailView {
    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_money_type)
    TextView txtMoneyType;
    @BindView(R.id.txt_money)
    TextView txtMoney;
    @BindView(R.id.txt_type)
    TextView txtType;
    @BindView(R.id.txt_time)
    TextView txtTime;
    @BindView(R.id.txt_transaction_number)
    TextView txtTransactionNumber;
    @BindView(R.id.txt_surplus_money)
    TextView txtSurplusMoney;
    @BindView(R.id.txt_remark)
    TextView txtRemark;

    private String type;
    private String token;
    private String id;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_deal_details);
        token = SharedPreferencesUtil.getsInstances(this).getLoginInfo().getToken();
        type = getIntent().getStringExtra("type");
        id = getIntent().getStringExtra("id");
    }

    @Override
    protected void initPresenter() {
        mPresenter = new DealDetailPresenter(this);
    }

    @Override
    protected void init() {
        setTopView();
        if (StringUtils.isEmpty(type)){
            if (type.equals("0")){
                mPresenter.getUserDetail(token, id);
            }else if (type.equals("1")){
                mPresenter.getStorDetail(token, id);
            }
        }
    }

    private void setTopView() {
        imgLeft.setImageResource(R.mipmap.icon_close_black);
        txtTitle.setText("交易明细");
    }

    @OnClick(R.id.ll_leftview)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void getUserDealDetail(DealDetailBean dealDetailBean) {
        txtMoney.setText(dealDetailBean.getMoney());
        txtMoneyType.setText("入账金额");
        txtRemark.setText(dealDetailBean.getContent());
        txtSurplusMoney.setText(dealDetailBean.getU_balance());
        txtTime.setText(dealDetailBean.getAdd_time());
        txtType.setText(dealDetailBean.getType());
        txtTransactionNumber.setText("");
    }

    @Override
    public void getStroDealDetail(DealDetailBean dealDetailBean) {
        txtMoney.setText(dealDetailBean.getMoney());
        txtRemark.setText(dealDetailBean.getContent());
        txtSurplusMoney.setText(dealDetailBean.getU_balance());
        txtTime.setText(dealDetailBean.getAdd_time());
        txtMoneyType.setText("入账金额");
        txtType.setText(dealDetailBean.getType());
        txtTransactionNumber.setText("");

    }
}
